package com.uchiha.nova.mainService.controller;

import com.google.common.collect.Lists;
import com.uchiha.nova.core.feign.RoleFeignService;
import com.uchiha.nova.core.model.dto.RoleDTO;
import com.uchiha.nova.core.model.query.RoleQuery;
import com.uchiha.nova.core.tool.api.R;
import com.uchiha.nova.core.tool.constant.NovaCRUDMethodConstant;
import com.uchiha.nova.core.tool.support.BaseController;
import com.uchiha.nova.core.tool.support.NovaUser;
import com.uchiha.nova.core.tool.support.QueryContext;
import com.uchiha.nova.core.tool.util.BeanToMapUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author 周林静
 * @Date 2025/4/23 15:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/role")
@Slf4j
@Tag(name = "角色管理的前端控制器")
public class RoleController extends BaseController {
    @Resource
    RoleFeignService roleFeignService;

    @Operation(summary = "分页查询")
    @GetMapping(NovaCRUDMethodConstant.NOVA_WEB_PAGE)
    public R getPage(RoleQuery query, QueryContext queryContext){
        NovaUser novaUser = getNovaUser();
        query.setTenantId(novaUser.getTenantId());
        List<Object> list = Lists.newArrayList(query,queryContext);
        Map<String,Object> map = BeanToMapUtil.beanToMap(list);
        return roleFeignService.getPage(map);
    }

    @Operation(summary = "详情")
    @GetMapping(NovaCRUDMethodConstant.NOVA_WEB_GETONE)
    public R getOne(RoleDTO roleDTO){
        NovaUser novaUser = getNovaUser();
        roleDTO.setTenantId(novaUser.getTenantId());
        return roleFeignService.detail(roleDTO);
    }

    @Operation(summary = "新增")
    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_SAVE)
    public R save(@RequestBody RoleDTO roleDTO){
        return roleFeignService.save(roleDTO);
    }

    @Operation(summary = "修改")
    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_UPDATE)
    public R update(@RequestBody RoleDTO roleDTO){
        return roleFeignService.update(roleDTO);
    }

    @Operation(summary = "新增或者修改")
    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_SAVEORUPDATE)
    public R saveOrUpdate(@RequestBody RoleDTO roleDTO){
        return roleFeignService.saveOrUpdate(roleDTO);
    }

    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_REMOVE)
    @Operation(summary = "逻辑删除")
    public R remove(@RequestParam String ids){
        return roleFeignService.remove(ids);
    }

    @Operation(summary = "物理删除")
    @DeleteMapping(NovaCRUDMethodConstant.NOVA_WEB_DELETE)
    public R delete(@RequestParam String ids){
        return roleFeignService.delete(ids);
    }

    @PostMapping("/list")
    public R list(@RequestBody RoleDTO roleDTO){
        return roleFeignService.getList(roleDTO);
    }
}
